package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.PageReq;
import com.itheima.entity.PageRes;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.apache.dubbo.config.annotation.Service;

import java.util.List;

@Service
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {
    @Override
    public boolean deleteById(Long id) {
        CheckItem checkItem = new CheckItem();
        checkItem.setId(id);
        checkItem.setIs_delete(1);
        this.updateById(checkItem);
        return true;
    }

    @Override
    public PageRes<CheckItem> page(PageReq pageReq) {
        //1.设置当前页面和页面大小
        Page<CheckItem> page = new Page<>();
        page.setCurrent(pageReq.getCurrentPage());//当前页
        page.setSize(pageReq.getPageSize());//页面大小

        //where name like '%测试%'
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete",0);
        if(pageReq.getQueryString() != null && "".equals(pageReq.getQueryString().trim()) == false)
            queryWrapper.like("name",pageReq.getQueryString());//like 模糊匹配

        //分页查询 limit
        IPage<CheckItem> ipage =  this.page(page,queryWrapper);

        //分页请求结果对象
        return new PageRes<>(ipage.getTotal(),ipage.getRecords());
    }

    @Override
    public List<CheckItem> selectByGroupId(Long groupId) {
        return this.baseMapper.selectByGroupId(groupId);
    }

}
